<template>
	<view
      style="user-select: text;"
      class="content">
    <view class="box">
      <view class="big-title">时间工具</view>
      <view class="test-area">
        <text class="title">时间转常用格式：</text>
        <text class="result">{{$kt.date.toCommonFormat(new Date())}}</text>
        <view class="desc">代码：$kt.date.toCommonFormat(new Date())</view>
      </view>

      <view class="test-area">
        <text class="title">时间转固定格式：</text>
        <text class="result">{{$kt.date.format(new Date(),'yyyy年MM月dd日 hh点mm分ss秒')}}</text>
        <view class="desc">代码：$kt.date.format(new Date(),'yyyy年MM月dd日 hh点mm分ss秒')</view>
      </view>

      <view
      style="font-size: 30rpx;margin-top: 40rpx;color: #999;"
      >·时间转输出格式·为同一个函数，为了给演示更好的效果，所以给不同的几个时间戳进行调用</view>
      <view class="test-area">
        <view>
          <text class="title">时间转输出格式-1：</text>
          <text class="result">{{$kt.date.readableDate(new Date().getTime() - 100000)}}</text>
          <view class="desc">时间戳：当前时间减去100000毫秒</view>
          <view class="desc">代码：$kt.date.readableDate(new Date().getTime() - 100000)</view>
        </view>
      </view>

      <view class="test-area">
        <view>
          <text class="title">时间转输出格式-2：</text>
          <text class="result">{{$kt.date.readableDate(new Date().getTime() - 10000000)}}</text>
        </view>
        <view class="desc">时间戳：当前时间减去10000000毫秒</view>
        <view class="desc">代码：$kt.date.readableDate(new Date().getTime() - 10000000)</view>
      </view>

      <view class="test-area">
        <view>
          <text class="title">时间转输出格式-3：</text>
          <text class="result">{{$kt.date.readableDate(984722400000)}}</text>
        </view>
        <view class="desc">时间戳：984722400000</view>
        <view class="desc">代码：$kt.date.readableDate(984722400000)</view>
      </view>

    </view>

    <view style="height: 100rpx"></view>

    <view class="box">
      <view class="big-title">算式工具</view>
      <view class="test-area">
        <text class="title">加法（0.1 + 0.2）：</text>
        <text class="result">{{$kt.math.add(0.1,0.2)}}</text>
        <view class="desc">代码：$kt.math.add(0.1,0.2)</view>
      </view>
      <view class="test-area">
        <text class="title">批量加法（99.21 + 0.1 + 0.2）：</text>
        <text class="result">{{$kt.math.batchAdd(99.21,0.1,0.2)}}</text>
        <view class="desc">代码：$kt.math.batchAdd(99.21,0.1,0.2)</view>
      </view>
      <view class="test-area">
        <text class="title">减法（99.3 - 0.1）：</text>
        <text class="result">{{$kt.math.sub(99.3,0.1)}}</text>
        <view class="desc">代码：$kt.math.sub(99.3,0.1)</view>
      </view>
      <view class="test-area">
        <text class="title">批量减法（99.21 - 0.1 - 0.2）：</text>
        <text class="result">{{$kt.math.batchSub(99.21,0.1,0.2)}}</text>
        <view class="desc">代码：$kt.math.batchSub(99.21,0.1,0.2)</view>
      </view>
      <view class="test-area">
        <text class="title">乘法（9.3 * 0.1）：</text>
        <text class="result">{{$kt.math.mul(9.3,0.1)}}</text>
        <view class="desc">代码：$kt.math.mul(9.3,0.1)</view>
      </view>
      <view class="test-area">
        <text class="title">批量乘法（9.3 * 0.1 * 0.2）：</text>
        <text class="result">{{$kt.math.batchMul(9.3,0.1,0.2)}}</text>
        <view class="desc">代码：$kt.math.batchMul(9.3,0.1,0.2)</view>
      </view>
      <view class="test-area">
        <text class="title">除法（9.3 / 0.1）：</text>
        <text class="result">{{$kt.math.div(9.3,0.1)}}</text>
        <view class="desc">代码：$kt.math.div(9.3,0.1)</view>
      </view>
      <view class="test-area">
        <text class="title">批量除法（9.3 / 0.1 / 0.2）：</text>
        <text class="result">{{ $kt.math.batchDiv(9.3, 0.1, 0.2)}}</text>
        <view class="desc">代码：$kt.math.batchDiv(9.3, 0.1, 0.2)</view>
      </view>
      <view class="test-area">
       <view>
         <text class="title">算式解释器：</text>
         <text class="result">{{$kt.math.evaluate('99.3 + 0.1 * (0.2 + 0.1)')}}</text>
       </view>
        <view class="desc">代码：$kt.math.evaluate('99.3 + 0.1 * (0.2 + 0.1)')</view>
      </view>
    </view>

    <view style="height: 100rpx"></view>
    <view class="box">
      <view class="big-title">RSA工具</view>
      <view class="test-area">
        <view>
          <text class="title">加密（RSA的kantboot格式加密）：</text>
          <view class="result">
            {{$kt.rsa.kantbootEncrypt("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC/2BE/3DlK3mL53EhXFe934pJpGRHU6YB+Nn+kNGVFve8Wa2CU+1K6pGzWRxsOMmDVWQFP0rzpKZAPg8LMEFZVCwoOjU4QmytAbRONL0JrYZ90jBOOs4DcqFSpkeNLsYkILSKI4adSuIN2bNTZGraTad0bDWK3OU+PIGy5e3WpAwIDAQAB","123456")}}
          </view>
        </view>
        <view class="desc">代码：$kt.rsa.kantbootEncrypt("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC/2BE/3DlK3mL53EhXFe934pJpGRHU6YB+Nn+kNGVFve8Wa2CU+1K6pGzWRxsOMmDVWQFP0rzpKZAPg8LMEFZVCwoOjU4QmytAbRONL0JrYZ90jBOOs4DcqFSpkeNLsYkILSKI4adSuIN2bNTZGraTad0bDWK3OU+PIGy5e3WpAwIDAQAB","123456")</view>
      </view>
      <view class="test-area">
        <view>
          <text class="title">加密（向服务器请求到公钥，直接加密）：</text>
          <view class="result">
            {{kantbootEncryptStrByServer}}
          </view>
          <view class="desc">使用该函数的前提条件：后端得使用KANTBOOT框架</view>
        </view>
      </view>
    </view>

    <view style="height: 100rpx"></view>
    <view class="box">
      <view class="big-title">用户工具</view>
      <view class="test-area">
        <text class="title">转换simple格式：</text>
        <view style="height: 10px"></view>
        <view class="result bg">
          <pre>
          {{$kt.user.formatSimple(user)}}
          </pre>
        </view>
        <view style="height: 10px"></view>
        <view class="desc">使用该函数的前提条件：后端得使用KANTBOOT框架</view>
        <view class="desc">代码：$kt.user.formatSimple(user)</view>
      </view>
    </view>

    <view style="height: 100rpx"></view>
    <view class="box">
      <view class="big-title">其它工具</view>
        <view class="test-area">
          <text class="title">生成UUID（使用默认长度[32位]）：</text>
          <view class="result">
            {{$kt.util.createUUID()}}
          </view>
          <view class="desc">代码：$kt.util.createUUID()</view>
      </view>
      <view class="test-area">
        <text class="title">生成UUID（自定义长度[128位]）：</text>
        <view class="result">
          {{$kt.util.createUUID(128)}}
        </view>
        <view class="desc">代码：$kt.util.createUUID(128)</view>
      </view>
      <view class="test-area">
        <text class="title">rpx转px（100rpx）：</text>
        <view class="result">
          {{$kt.util.rpxToPx(100)}}
        </view>
        <view class="desc">代码：$kt.util.rpxToPx(100)</view>
      </view>
      <view class="test-area">
        <text class="title">px转rpx（100px）：</text>
        <view class="result">
          {{$kt.util.pxToRpx(100)}}
        </view>
      </view>
      <view class="test-area">
        <text class="title">距离转输出格式（参数单位：米[1600米]）：</text>
        <view class="result">
          {{$kt.util.readableDistance(1600)}}
        </view>
        <view class="desc">代码：$kt.util.readableDistance(1600)</view>
      </view>
      <view class="test-area">
        <text class="title">新JSON对象：</text>
        <view class="result">
          {{$kt.util.newJSON(jsonDemo)}}
        </view>
        <view class="desc">
          该函数用途：当你需要将一个对象转换成另一个对象，但是又不想影响原对象的时候，可以使用该函数。
        </view>
        <view class="desc">代码：$kt.util.newJSON(jsonDemo)</view>
      </view>
    </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
        /**
         * 向服务器请求到公钥，直接加密
         * 赋值的字符串
         */
        kantbootEncryptStrByServer: '',
        jsonDemo:{
          username:"admin",
          roleCodes:['admin','user']
        },
        user: {
          "directCode": null,
          "email": null,
          "fileIdOfAvatar": null,
          "genderCode": null,
          "gmtCreate": 1706026637921,
          "gmtModified": 1706026637921,
          "id": 507336443625477,
          "introduction": null,
          "inviteCode": null,
          "inviteUserId": null,
          "isInit": null,
          "isTemporary": null,
          "nickname": null,
          "phone": null,
          "userBalance": [],
          "userOnline": {
            "gmtCreate": null,
            "gmtLastHeartbeat": 1706308785491,
            "gmtLastOffline": null,
            "gmtLastOnline": 1706308807909,
            "gmtModified": 1706308807912,
            "isInvisible": false,
            "isOnline": false,
            "userId": 507336443625477
          },
          "userRoleList": [
            {
              "gmtCreate": null,
              "gmtModified": null,
              "id": 1,
              "roleCode": "systemAdmin",
              "userId": 507336443625477,
              "visible": null
            },
            {
              "gmtCreate": null,
              "gmtModified": 1706026638445,
              "id": 507336445788165,
              "roleCode": "user",
              "userId": 507336443625477,
              "visible": null
            }
          ],
          "username": "admin01"
        }
			}
		},
		created() {
      this.kantbootEncryptByServer();
		},
		methods: {
      /**
       * 向服务器请求到公钥，直接加密
       */
      kantbootEncryptByServer(){
        let encryptStr = "123456";
        this.$kt.rsa.kantbootEncryptByServer(encryptStr).then(res=>{
          this.kantbootEncryptStrByServer = res
        })
      }
		}
	}
</script>

<style lang="scss" scoped>

  .content{
    padding: 20px;
  }

  .big-title{
    font-size: 40rpx;
    font-weight: bold;
  }

  .test-area{
    margin-top: 10px;
    font-size: 30rpx;
  }

  .title{
    font-weight: bold;
  }

  .result{
    flex: 1;
    // 超出换行
    word-wrap: break-word;
  }

  .desc{
    color: #999;
    font-size: 24rpx;
    // 超出换行
    word-wrap: break-word;
  }

  .bg{
    background-color: #f5f5f5;
    padding: 10px;
    border-radius: 10px;
  }
</style>
